import {
  Toast
} from "mint-ui";
export default {
  install(Vue, options) {
    // 获取用户信息
    Vue.prototype.baseUserMessageDistributeFun = function (val) {
      if (window.BenchJSInterface) {
        if (window.BenchJSInterface.getUserToken) {
          window.BenchJSInterface.getUserToken(
            "javascript:window.getAppgetUserToken(->path<-);"
          );
        }
      }
    };
    Vue.prototype.baseUserInfoFun = function (val) {
      let userobj = JSON.parse(JSON.stringify(val));
      let user = {};
      user = {
        token: userobj.token,
        userOrgList: userobj.userOrgList,
      };
      sessionStorage.setItem("TOKEN", user.token);
      sessionStorage.setItem("USERORGLIST", JSON.stringify(user.userOrgList));
    };
    // 获取组织机构
    Vue.prototype.baseUserchooseOrgFun = function (params, str) {
      if (window.BenchJSInterface) {
        if (window.BenchJSInterface.chooseOrg) {
          window.BenchJSInterface.chooseOrg(
            params,
            `javascript:window.${str}(->path<-);`
          );
        }
      }
    };
    Vue.prototype.basechooseOrgInfoFun = function (val) {
      let userobj = JSON.parse(JSON.stringify(val));
      return userobj
    };
    // 退出
    Vue.prototype.baseBackFun = function () {
      if (window.BenchJSInterface) {
        window.BenchJSInterface.finishWebActivity();
      }
    };
    // Tost
    Vue.prototype.baseToastFun = function (val = "服务器异常") {
      Toast({
        message: val,
        position: "bottom"
      });
    };
    // 跳转route
    Vue.prototype.basePushFun = function (val = "/") {
      this.$router.push({
        path: val
      });
    };
    // 设置标题
    /**
     *title : 导航名称
     */
    Vue.prototype.titleFun = function (M) {
      document.title = M.title || "";
      if (window.BenchJSInterface) {
        if (window.BenchJSInterface.setTitle) {
          window.BenchJSInterface.setTitle(M.title || "");
        }
      }
    };
    // 选择
    Vue.prototype.userListFun = function (M) {
      if (window.BenchJSInterface) {
        if (M.lists.length > 0) {
          window.BenchJSInterface.setLargeMaxMembers(
            "101",
            `javascript:window.${M.path}(->path<-);`,
            JSON.stringify(M.lists),
            M.limitCount,
            M.canSelectSelf || 0
          );
        } else {
          window.BenchJSInterface.setLargeMaxMembers(
            "101",
            `javascript:window.${M.path}(->path<-);`,
            M.limitCount,
            M.canSelectSelf || 0
          );
        }
      }
    };
    // 
    Vue.prototype.baseDateFun = function (val) {
      if (val) {
        var standardTime = new Date(Number(val));
        var y, m, d, h, f;
        y = standardTime.getFullYear();
        m = standardTime.getMonth() + 1;
        m = m > 9 ? m : "0" + m;
        d = standardTime.getDate();
        d = d > 9 ? d : "0" + d;
        h = standardTime.getHours();
        h = h > 9 ? h : "0" + h;
        f = standardTime.getMinutes();
        f = f > 9 ? f : "0" + f;
        return y + "-" + m + "-" + d;
      } else {
        return "暂无";
      }
    };
    // 
    Vue.prototype.baseDateTjFun = function (val) {
      if (val) {
        var standardTime = new Date(Number(val));
        var y, m, d, h, f;
        y = standardTime.getFullYear();
        m = standardTime.getMonth() + 1;
        m = m > 9 ? m : "0" + m;
        d = standardTime.getDate();
        d = d > 9 ? d : "0" + d;
        h = standardTime.getHours();
        h = h > 9 ? h : "0" + h;
        f = standardTime.getMinutes();
        f = f > 9 ? f : "0" + f;
        return y + "-" + m
      } else {
        return "暂无";
      }
    };
  }
};
